﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class ButtenEventTriggerListener : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
{
    public static ButtenEventTriggerListener Get(GameObject go)
    {
        ButtenEventTriggerListener listener = go.GetComponent<ButtenEventTriggerListener>();
        if (listener == null) listener = go.AddComponent<ButtenEventTriggerListener>();
        return listener;
    }
    public delegate void ButtonEventDelegate(GameObject go, PointerEventData eventData);

    public event ButtonEventDelegate onPointerEnter;
    public event ButtonEventDelegate onPointerExit;
    public event ButtonEventDelegate onPointerDown;
    public event ButtonEventDelegate onPointerUp;
    public event ButtonEventDelegate onPointerClick;

    public virtual void OnPointerClick(PointerEventData eventData)
    {
        if (onPointerClick != null) onPointerClick(gameObject, eventData);
    }

    public virtual void OnPointerDown(PointerEventData eventData)
    {
        if (onPointerDown != null) onPointerDown(gameObject, eventData);
    }

    public virtual void OnPointerEnter(PointerEventData eventData)
    {
        if (onPointerEnter != null) onPointerEnter(gameObject, eventData);
    }

    public virtual void OnPointerExit(PointerEventData eventData)
    {
        if (onPointerExit != null) onPointerExit(gameObject, eventData);
    }

    public virtual void OnPointerUp(PointerEventData eventData)
    {
        if (onPointerUp != null) onPointerUp(gameObject, eventData);
    }
}
